package com.lill.sale.web;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lill.common.component.util.R;
import com.lill.sale.service.IRoyaltyOfSaleService;
import com.lill.support.annotation.CurrentUser;
import com.lill.system.model.SysUserEntity;

/**
 * 销售提成值Controller
 *
 * @author lill
 * @date 2021-09-06 20:23:17
 */
@RestController
@RequestMapping("sale/royalty")
public class SaleRoyaltyController {
	
    @Autowired
    private IRoyaltyOfSaleService royaltyOfSaleService;

    /**
     * 查看信息
     */
    @RequestMapping("/info")
    public R info(@RequestParam String saleCarId,@RequestParam String productCarId) {
    	Map<String, Object> royaltyMap = royaltyOfSaleService.queryObject(saleCarId,productCarId);
        return R.ok().put("productRoyalty", royaltyMap);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Map<String, Object> productRoyalty,@CurrentUser SysUserEntity user) {
    	productRoyalty.put("company_id", user.getCompanyId());
    	productRoyalty.put("branch_id", user.getBranchId());
        int result=royaltyOfSaleService.save(productRoyalty);
		if(result>0){
        	return R.ok();
        }else{
        	return R.failure();
        }
    }

}
